#include "stringUnit.h"

std::vector<std::string> split(std::string str, std::string splitStr)
{
	std::vector<std::string> stringVector;

	int index1 = 0;
	int index2 = 0;
	int size = splitStr.length();
	while (true)
	{
		index2 = str.find(splitStr, index1);

		if (index2 != std::string::npos) {
			std::string temp = str.substr(index1, index2-index1);
				stringVector.push_back(temp);
		}
		else{
			std::string temp = str.substr(index1, str.length() - index1);
				stringVector.push_back(temp);
			break;
		}

		index1 = index2 + size;
	}
	return stringVector;
}

std::string SHA1code(std::string str)
{
	std::string distStr;
	CryptoPP::SHA1 hash;
	CryptoPP::StringSource(str, true, new CryptoPP::HashFilter(hash, new CryptoPP::StringSink(distStr)));
	return distStr;
}

std::string BASE64code(std::string str)
{
	std::string encoded;

	CryptoPP::StringSource ss(str, true,
		new CryptoPP::Base64Encoder(
			new CryptoPP::StringSink(encoded)
		) // Base64Encoder
	);
	return encoded;
}
